#ifndef AILINESELECTOR_H
#define AILINESELECTOR_H

#include <QObject>
#include <QLine>
#include <QList>

class DotController;
class Cell;
class Line;
class CellLinePair;

class AILineSelector : public QObject
{
Q_OBJECT
public:
    AILineSelector(DotController *pController, QObject *parent = 0);

    virtual void sort(QList<Cell*> &cells) = 0;

public slots:
    QLine selectLine();
    void gameStarted();

private:
    void initParam();
    Line *addLine(QLine line);
    void removeLine(Line *pLine);
    QLine tryToFindAdjacentLine(QList<Cell*> &cellsAdjacent);
    QLine tryToFindOptimizeLine(QList<Cell *> &cellsAdjacent,uint &nMinCellFillup);
    void continuousSearchForFindingCellOwned(uint &nMinCellOwned,QLine &nMinLine,QLine startLine);
    QLine considerExtremeMode(QList<Cell *> &cellsOwnableNow);
    bool applyExtremeTrick(QList< QList< CellLinePair* > > &clp2d,uint nMinCellOwned);
    void winableCellsInThisTurn(QList<Cell *> cellsOwnableNow,QList< QList< CellLinePair* > > &clp2d,uint &nTotal,uint &nMax);
    void winCellRecursively(Cell *pCell, QList<CellLinePair *> &cellLinePair);

private:
    DotController *mpController;
    uint mnMinCellToFind;
    QList<QLine> mLinesPreCalculated;
    bool mbPreCalculated ;

    friend class CellLinePair;
};

#endif // AILINESELECTOR_H
